package zhai.git;

import java.util.concurrent.TimeUnit;
// jps -l
// jstack 23790
public class DeadLock {

    public static void main(String[] args) {
        String a = "1";
        String b = "2";
        new Thread(new A(a,b)).start();
        new Thread(new A(b,a)).start();
    }

    static class A implements Runnable {

        private String a;

        private String b;

        public A(String a, String b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public void run() {
            synchronized (a) {
                System.out.println("A is lock");
                try {
                    TimeUnit.SECONDS.sleep(2);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (b) {
                    System.out.println("B is lock");
                }
            }
        }
    }

}
